package xcmg.device.web.ratingManager;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xcmg.device.infra.BasicController;
import xcmg.device.infra.ErrorCode;
import xcmg.device.service.ratingManager.MarketDealerRatingService;
import xcmg.device.service.vo.ratingManager.MarketingDealerRatingAddVO;
import xcmg.device.service.vo.ratingManager.MarketingDealerRatingVO;
import yb.ecp.fast.infra.annotation.FastMappingInfo;
import yb.ecp.fast.infra.infra.ActionResult;

import java.util.List;

/**
 * Created by Administrator on 2019/7/15.
 */
@RestController
@RequestMapping("/marketDealerRating")
@Api("评级制定")
public class MarketDealerRatingController extends BasicController {
    @Autowired
    private MarketDealerRatingService marketDealerRatingService;

    @PostMapping(value = "/add")
    @ApiOperation(value = "新增评级")
    @FastMappingInfo(needLogin = true)
    public ActionResult add(@RequestBody MarketingDealerRatingAddVO addVO) throws Exception {
        List<MarketingDealerRatingVO> marketingDealerList = addVO.getMarketingDealerList();
        String ratingId = addVO.getRatingId();
        if (StringUtils.isBlank(ratingId) || null == marketingDealerList || marketingDealerList.isEmpty()) {
            return actionResult(ErrorCode.IllegalArument);
        }
        ErrorCode add = marketDealerRatingService.add(addVO, getOrgId());
        return actionResult(add);
    }

    @PostMapping(value = "/update")
    @ApiOperation(value = "修改评级")
    @FastMappingInfo(needLogin = true)
    public ActionResult update(@RequestBody MarketingDealerRatingAddVO addVO) throws Exception {
        List<MarketingDealerRatingVO> marketingDealerList = addVO.getMarketingDealerList();
        String ratingId = addVO.getRatingId();
        if (StringUtils.isBlank(ratingId) || null == marketingDealerList || marketingDealerList.isEmpty()) {
            return actionResult(ErrorCode.IllegalArument);
        }
        ErrorCode add = marketDealerRatingService.addOrUpdate(addVO, getOrgId());
        return actionResult(add);
    }

    @GetMapping(value = "/list")
    @ApiOperation(value = "获取评级信息")
    @FastMappingInfo(needLogin = true)
    public ActionResult list(@RequestParam("ratingId") String ratingId) throws Exception {
        if (StringUtils.isBlank(ratingId)) {
            return actionResult(ErrorCode.IllegalArument);
        }

        return actionValueResult(marketDealerRatingService.list(ratingId));
    }

}
